package com.onepiece.shipelves.common.ticker;


import com.alibaba.fastjson.JSONArray;
import com.onepiece.shipelves.common.enums.SystemExceptionEnum;
import com.onepiece.shipelves.common.utils.JsonUtil;

/**
 * @author wangxj
 * @Desc: 合约资金大小单，
 * @date 2019-07-08
 */
public class FutureFundOrder {

    /**
     * burst:爆仓
     * deal:成交
     */
    private Integer smallManyBurst = 0;
    private Integer middleManyBurst = 0;
    private Integer bigManyBurst = 0;
    private Integer superManyBurst = 0;
    private Integer smallEmptyBurst = 0;
    private Integer middleEmptyBurst = 0;
    private Integer bigEmptyBurst = 0;
    private Integer superEmptyBurst = 0;
    private Integer smallManyDeal = 0;
    private Integer middleManyDeal = 0;
    private Integer bigManyDeal = 0;
    private Integer superManyDeal = 0;
    private Integer smallEmptyDeal = 0;
    private Integer middleEmptyDeal = 0;
    private Integer bigEmptyDeal = 0;
    private Integer superEmptyDeal = 0;

    private Boolean isInitialize = false;


    public FutureFundOrder() {
    }

    public FutureFundOrder(JSONArray burst, JSONArray deal, String key) {
        for (int i = 0; i < 6; i++) {
            JSONArray dealArray = deal.getJSONArray(i);
            setValue(i, burst, dealArray);
            this.isInitialize = true;
        }
    }

    public FutureFundOrder(JSONArray burst, JSONArray deal, String key, Integer time) {
        for (int i = 0; i < 6; i++) {
            JSONArray dealArray = deal.getJSONArray(i);
            if (dealArray.getInteger(8) > time) {
                if (!this.isInitialize) {
                    this.isInitialize = true;
                }
                setValue(i, burst, dealArray);
            }
        }
    }

    public FutureFundOrder(JSONArray burst, JSONArray deal) {
        for (int i = 0; i < 6; i++) {
            JSONArray dealArray = deal.getJSONArray(i);
            setValue(i, burst, dealArray);
            this.isInitialize = true;
        }
    }

    public FutureFundOrder(JSONArray burst, JSONArray deal, Integer time) {
        for (int i = 0; i < 6; i++) {
            JSONArray dealArray = deal.getJSONArray(i);
            if (dealArray.getInteger(8) > time) {
                if (!this.isInitialize) {
                    this.isInitialize = true;
                }
                setValue(i, burst, dealArray);
            }
        }
    }

    public void addAnother(FutureFundOrder another) {
        this.isInitialize = true;
        this.smallManyBurst += another.getSmallManyBurst();
        this.middleManyBurst += another.getMiddleManyBurst();
        this.bigManyBurst += another.getBigManyBurst();
        this.superManyBurst += another.getSuperManyBurst();
        this.smallEmptyBurst += another.getSmallEmptyBurst();
        this.middleEmptyBurst += another.getMiddleEmptyBurst();
        this.bigEmptyBurst += another.getBigEmptyBurst();
        this.superEmptyBurst += another.getSuperEmptyBurst();
        this.smallManyDeal += another.getSmallManyDeal();
        this.middleManyDeal += another.getMiddleManyDeal();
        this.bigManyDeal += another.getBigManyDeal();
        this.superManyDeal += another.getSuperManyDeal();
        this.smallEmptyDeal += another.getSmallEmptyDeal();
        this.middleEmptyDeal += another.getMiddleManyDeal();
        this.bigEmptyDeal += another.getBigEmptyDeal();
        this.superEmptyDeal += another.getSuperEmptyDeal();
    }

    private void setValue(Integer i, JSONArray burst, JSONArray dealArray) {
        JSONArray burstArray = burst.getJSONArray(i);
        this.smallManyBurst += burstArray.getInteger(0);
        this.middleManyBurst += burstArray.getInteger(1);
        this.bigManyBurst += burstArray.getInteger(2);
        this.superManyBurst += burstArray.getInteger(3);
        this.smallEmptyBurst += burstArray.getInteger(4);
        this.middleEmptyBurst += burstArray.getInteger(5);
        this.bigEmptyBurst += burstArray.getInteger(6);
        this.superEmptyBurst += burstArray.getInteger(7);
        this.smallManyDeal += dealArray.getInteger(0);
        this.middleManyDeal += dealArray.getInteger(1);
        this.bigManyDeal += dealArray.getInteger(2);
        this.superManyDeal += dealArray.getInteger(3);
        this.smallEmptyDeal += dealArray.getInteger(4);
        this.middleEmptyDeal += dealArray.getInteger(5);
        this.bigEmptyDeal += dealArray.getInteger(6);
        this.superEmptyDeal += dealArray.getInteger(7);
    }


    public Integer getSumDeal() {
        return smallManyDeal + middleManyDeal + bigManyDeal + superManyDeal + smallEmptyDeal + middleEmptyDeal + bigEmptyDeal + superEmptyDeal;
    }

    public Integer getSumBurst() {
        return smallManyBurst + middleManyBurst + bigManyBurst + superManyBurst + smallEmptyBurst + middleEmptyBurst + bigEmptyBurst + superEmptyBurst;
    }

    public Integer getSum(String type) {
        if ("burst".equals(type)) {
            return getSumBurst();
        } else if ("deal".equals(type)) {
            return getSumDeal();
        }
        throw SystemExceptionEnum.ILLEGAL_REQUEST_PARAM.ex;
    }

    public Integer getSmallManyBurst() {
        return smallManyBurst;
    }

    public void setSmallManyBurst(Integer smallManyBurst) {
        this.smallManyBurst = smallManyBurst;
    }

    public Integer getMiddleManyBurst() {
        return middleManyBurst;
    }

    public void setMiddleManyBurst(Integer middleManyBurst) {
        this.middleManyBurst = middleManyBurst;
    }

    public Integer getBigManyBurst() {
        return bigManyBurst;
    }

    public void setBigManyBurst(Integer bigManyBurst) {
        this.bigManyBurst = bigManyBurst;
    }

    public Integer getSuperManyBurst() {
        return superManyBurst;
    }

    public void setSuperManyBurst(Integer superManyBurst) {
        this.superManyBurst = superManyBurst;
    }

    public Integer getSmallEmptyBurst() {
        return smallEmptyBurst;
    }

    public void setSmallEmptyBurst(Integer smallEmptyBurst) {
        this.smallEmptyBurst = smallEmptyBurst;
    }

    public Integer getMiddleEmptyBurst() {
        return middleEmptyBurst;
    }

    public void setMiddleEmptyBurst(Integer middleEmptyBurst) {
        this.middleEmptyBurst = middleEmptyBurst;
    }

    public Integer getBigEmptyBurst() {
        return bigEmptyBurst;
    }

    public void setBigEmptyBurst(Integer bigEmptyBurst) {
        this.bigEmptyBurst = bigEmptyBurst;
    }

    public Integer getSuperEmptyBurst() {
        return superEmptyBurst;
    }

    public void setSuperEmptyBurst(Integer superEmptyBurst) {
        this.superEmptyBurst = superEmptyBurst;
    }

    public Integer getSmallManyDeal() {
        return smallManyDeal;
    }

    public void setSmallManyDeal(Integer smallManyDeal) {
        this.smallManyDeal = smallManyDeal;
    }

    public Integer getMiddleManyDeal() {
        return middleManyDeal;
    }

    public void setMiddleManyDeal(Integer middleManyDeal) {
        this.middleManyDeal = middleManyDeal;
    }

    public Integer getBigManyDeal() {
        return bigManyDeal;
    }

    public void setBigManyDeal(Integer bigManyDeal) {
        this.bigManyDeal = bigManyDeal;
    }

    public Integer getSuperManyDeal() {
        return superManyDeal;
    }

    public void setSuperManyDeal(Integer superManyDeal) {
        this.superManyDeal = superManyDeal;
    }

    public Integer getSmallEmptyDeal() {
        return smallEmptyDeal;
    }

    public void setSmallEmptyDeal(Integer smallEmptyDeal) {
        this.smallEmptyDeal = smallEmptyDeal;
    }

    public Integer getMiddleEmptyDeal() {
        return middleEmptyDeal;
    }

    public void setMiddleEmptyDeal(Integer middleEmptyDeal) {
        this.middleEmptyDeal = middleEmptyDeal;
    }

    public Integer getBigEmptyDeal() {
        return bigEmptyDeal;
    }

    public void setBigEmptyDeal(Integer bigEmptyDeal) {
        this.bigEmptyDeal = bigEmptyDeal;
    }

    public Integer getSuperEmptyDeal() {
        return superEmptyDeal;
    }

    public void setSuperEmptyDeal(Integer superEmptyDeal) {
        this.superEmptyDeal = superEmptyDeal;
    }

    public Boolean getInitialize() {
        return isInitialize;
    }

    public void setInitialize(Boolean initialize) {
        isInitialize = initialize;
    }

    @Override
    public String toString() {
        return JsonUtil.toJson(this);
    }
}
